using HKB.Common;
using System;
using System.Data;
using System.Data.SqlClient;
using System.Web;
namespace HKB.Web.DataHelper
{
	public class Shop_Witkey
	{
		private Conn conn = null;
		public Shop_Witkey(Conn _conn)
		{
			this.conn = _conn;
		}
		public Shop_Witkey()
		{
			this.conn = Text.GetComponent<Conn>("conn", HttpContext.Current.CurrentHandler);
		}
		public DataTable GetWitkeyTypeByTypeFId(int TypeFId)
		{
			return this.conn.GetDataTable("select * from [HLWitkey_Type] where [Type_FId] = " + TypeFId);
		}
		public DataTable GetWitkeyTypeOneAll()
		{
			string sql = string.Empty;
			sql = "SELECT distinct [Type_FId],CASE WHEN [Type_FId] =0 THEN '平面包装 ' WHEN [Type_FId] =1 THEN '网站/软件' WHEN [Type_FId] =2 THEN '策划/文案' WHEN [Type_FId] =3 THEN '劳务/营销' WHEN [Type_FId] =4 THEN '工造/产品' WHEN [Type_FId] =5 THEN '建筑/装饰' WHEN [Type_FId] =6 THEN '其它的'   END AS [TypeOne] FROM [HLWitkey_Type] ";
			return this.conn.GetDataTable(sql);
		}
		public DataTable GetWitkeyMessage(int WitkeyId)
		{
			string sql = string.Empty;
			sql = "SELECT [Message_Id],[Message_WitkeyId],[Message_Uid],[Message_Date],[Message_Desc],[UserName] FROM [HLWitkey_Message],[HL_User] WHERE Message_Uid = UserId AND Message_WitkeyId = " + WitkeyId + " ORDER BY Message_Date DESC";
			return this.conn.GetDataTable(sql);
		}
		public DataTable AddWitkeyMessage(int Message_WitkeyId, int Message_Uid, DateTime Message_Date, string Message_Desc)
		{
			SqlParameter[] array = new SqlParameter[4];
			array[0] = new SqlParameter("@Message_WitkeyId", DbType.Int32);
			array[0].Value = Message_WitkeyId;
			array[1] = new SqlParameter("@Message_Uid", DbType.Int32);
			array[1].Value = Message_Uid;
			array[2] = new SqlParameter("@Message_Date", DbType.DateTime);
			array[2].Value = Message_Date;
			array[3] = new SqlParameter("@Message_Desc", DbType.String);
			array[3].Value = Message_Desc;
			return this.conn.GetDataTable("PR_AddWitkeyMessage", array);
		}
		public DataTable GetWitkeyUserInfo(int UserId)
		{
			string sql = string.Empty;
			sql = "SELECT * FROM [HLWitkey_UserInfo] WHERE [User_Uid] =" + UserId;
			return this.conn.GetDataTable(sql);
		}
		public DataTable AddWitkeyUserInfo(int User_Uid, int User_WinCount)
		{
			SqlParameter[] array = new SqlParameter[2];
			array[0] = new SqlParameter("@User_Uid", DbType.Int32);
			array[0].Value = User_Uid;
			array[1] = new SqlParameter("@User_WinCount", DbType.Int32);
			array[1].Value = User_WinCount;
			return this.conn.GetDataTable("PR_AddWitkeyUserInfo", array);
		}
		public void UpdateWitkeyUserInfo(int User_Uid)
		{
			SqlParameter[] array = new SqlParameter[]
			{
				new SqlParameter("@User_Uid", DbType.Int32)
			};
			array[0].Value = User_Uid;
			this.conn.Execute("PR_UpdateWitkeyUserInfo", array);
		}
		public DataTable GetWitkeyWork(int WitkeyId)
		{
			string sql = string.Empty;
			sql = "SELECT [work_Id],[work_WitkeyId],[work_Uid],[work_UserName],[work_Title], [work_Desc],[work_File],[work_Date],[work_statu],[User_WinCount],[Email],[UserName],[RegTime] ,CASE WHEN GroupID = 1 THEN '普通会员' WHEN GroupID = 2 THEN 'VIP贵宾' WHEN [GroupID] = 3 THEN '高级会员' END AS [GroupName] FROM [HLWitkey_Work],[HLWitkey_UserInfo],[HL_User]  WHERE [User_Uid] = [work_Uid] AND [work_Uid] = [UserID] AND [User_Uid] = [UserID] AND work_WitkeyId =" + WitkeyId + " ORDER BY work_Date DESC";
			return this.conn.GetDataTable(sql);
		}
		public DataTable GetWitkeyWorkUser(int WitkeyId, int Uid)
		{
			string sql = string.Empty;
			sql = string.Concat(new object[]
			{
				"SELECT [work_Id],[work_WitkeyId],[work_Uid],[work_UserName],[work_Title], [work_Desc],[work_File],[work_Date],[work_statu],[User_WinCount],[Email],[UserName],[RegTime] ,CASE WHEN GroupID = 1 THEN '普通会员' WHEN GroupID = 2 THEN 'VIP贵宾' WHEN [GroupID] = 3 THEN '高级会员' END AS [GroupName] FROM [HLWitkey_Work],[HLWitkey_UserInfo],[HL_User]  WHERE [User_Uid] = [work_Uid] AND [work_Uid] = [UserID] AND [User_Uid] = [UserID] AND work_WitkeyId =",
				WitkeyId,
				" AND work_Uid = ",
				Uid,
				" ORDER BY work_Date DESC"
			});
			return this.conn.GetDataTable(sql);
		}
		public DataTable GetWitkeyWorkStatu(int WitkeyId, int Statu)
		{
			string sql = string.Empty;
			sql = string.Concat(new object[]
			{
				"SELECT [work_Id],[work_Uid],[work_statu],[UserName],[work_Date] FROM [HLWitkey_Work],[HL_User]  WHERE  [work_Uid] = [UserID]  AND work_WitkeyId =",
				WitkeyId,
				" AND work_statu = ",
				Statu,
				" ORDER BY work_Date DESC"
			});
			return this.conn.GetDataTable(sql);
		}
		public void UpdateWitkeyWorkStatu(int work_Id, int WitkeyId, int Statu)
		{
			string sql = string.Empty;
			sql = string.Concat(new string[]
			{
				"UPDATE [HLWitkey_Work] SET [work_statu] =  ",
				Statu.ToString(),
				" WHERE [work_WitkeyId] = ",
				WitkeyId.ToString(),
				" AND [work_Id] = ",
				work_Id.ToString()
			});
			this.conn.Execute(sql);
		}
		public DataTable AddWitkeyWork(int work_WitkeyId, int work_Uid, string work_UserName, string work_Title, string work_Desc, string work_File, DateTime work_Date, int work_statu)
		{
			SqlParameter[] array = new SqlParameter[8];
			array[0] = new SqlParameter("@work_WitkeyId", DbType.Int32);
			array[0].Value = work_WitkeyId;
			array[1] = new SqlParameter("@work_Uid", DbType.Int32);
			array[1].Value = work_Uid;
			array[2] = new SqlParameter("@work_UserName", DbType.String);
			array[2].Value = work_UserName;
			array[3] = new SqlParameter("@work_Title", DbType.String);
			array[3].Value = work_Title;
			array[4] = new SqlParameter("@work_Desc", DbType.String);
			array[4].Value = work_Desc;
			array[5] = new SqlParameter("@work_File", DbType.String);
			array[5].Value = work_File;
			array[6] = new SqlParameter("@work_Date", DbType.DateTime);
			array[6].Value = work_Date;
			array[7] = new SqlParameter("@work_statu", DbType.Int32);
			array[7].Value = work_statu;
			return this.conn.GetDataTable("PR_AddWitkeyWork", array);
		}
		public void UpdateWitkeyWork(int work_Id, int work_WitkeyId, string work_Title, string work_Desc, string work_File, int work_statu)
		{
			SqlParameter[] array = new SqlParameter[6];
			array[0] = new SqlParameter("@work_Id", DbType.Int32);
			array[0].Value = work_Id;
			array[1] = new SqlParameter("@work_WitkeyId", DbType.Int32);
			array[1].Value = work_WitkeyId;
			array[2] = new SqlParameter("@work_Title", DbType.String);
			array[2].Value = work_Title;
			array[3] = new SqlParameter("@work_Desc", DbType.String);
			array[3].Value = work_Desc;
			array[4] = new SqlParameter("@work_File", DbType.String);
			array[4].Value = work_File;
			array[5] = new SqlParameter("@work_statu", DbType.Int32);
			array[5].Value = work_statu;
			this.conn.Execute("PR_UpdateWitkeyWork", array);
		}
		public DataTable GetWitkey(int wwId)
		{
			string sql = string.Empty;
			sql = "SELECT [ww_Id],[ww_Type],[ww_Mode],[ww_xsModel],[ww_Title] ,[ww_Content],[ww_WitkeyTypeOne],[ww_WitkeyTypeTwo] ,[ww_Uid],[ww_UserName],[ww_StartTime],[ww_EndTime],[ww_zbPrice],[ww_xsPrice],[ww_Participants],[ww_Complete],[ww_Top],[ww_Url],[ww_Email],  [ww_Phone] ,CASE WHEN [ww_Statu] =1 THEN '未付款' WHEN [ww_Statu] =2 THEN '待审核' WHEN [ww_Statu] =3 THEN '审核失败'  WHEN [ww_Statu] =4 THEN '进行中' WHEN [ww_Statu] =5 THEN '公示中' WHEN [ww_Statu] =6 THEN '投票中' WHEN [ww_Statu] =7 THEN '任务失败'  WHEN [ww_Statu] =8 THEN '任务结束' WHEN [ww_Statu] =9 THEN '冻结' END AS [ww_Statu]  FROM [HLWitkey_Witkey] WHERE [ww_Id] = " + wwId + " ORDER BY ww_StartTime DESC";
			return this.conn.GetDataTable(sql);
		}
		public DataTable GetWitkeyAll()
		{
			string sql = string.Empty;
			sql = "SELECT * FROM [HLWitkey_Witkey]";
			return this.conn.GetDataTable(sql);
		}
		public void DeleteWitkey(int ww_Id)
		{
			string sql = string.Empty;
			sql = "DELETE FROM [HLWitkey_Witkey] WHERE ww_Id =" + ww_Id;
			this.conn.Execute(sql);
		}
		public DataTable GetWitkeyAllByWhere(string ww_Id, int ww_Type, string ww_WitkeyTypeOne, string ww_Statu, int ww_IdUp, int ww_StartTimeUp, int ww_EndTimeUp)
		{
			string text = string.Empty;
			text = "SELECT [ww_Id],[ww_Title],[ww_WitkeyTypeOne],[ww_StartTime],[ww_EndTime],[UserName] ,CASE WHEN [ww_Statu] =1 THEN '未付款' WHEN [ww_Statu] =2 THEN '待审核' WHEN [ww_Statu] =3 THEN '审核失败'   WHEN [ww_Statu] =4 THEN '进行中' WHEN [ww_Statu] =5 THEN '公示中' WHEN [ww_Statu] =6 THEN '投票中' WHEN [ww_Statu] =7 THEN '任务失败'  WHEN [ww_Statu] =9 THEN '冻结' WHEN [ww_Statu] =8 THEN '任务结束' END AS [ww_Statu]   FROM [HLWitkey_Witkey],[HL_User] WHERE [UserID] = [ww_Uid]";
			if (ww_Statu != "0")
			{
				if (ww_Id.Trim() != "")
				{
					text = text + " AND [ww_Id] = '" + ww_Id + "'";
				}
				if (ww_Type != 0)
				{
					text = text + " AND [ww_Type] = " + ww_Type;
				}
				if (ww_WitkeyTypeOne != "")
				{
					text = text + " AND [ww_WitkeyTypeOne] = '" + ww_WitkeyTypeOne + "'";
				}
				if (ww_Statu != "-1")
				{
					text = text + " AND [ww_Statu] = " + ww_Statu;
				}
				if (ww_IdUp == 1)
				{
					text += "ORDER BY [ww_Id] ASC";
				}
				else
				{
					if (ww_IdUp == 2)
					{
						text += "ORDER BY [ww_Id] DESC";
					}
				}
				if (ww_StartTimeUp == 1)
				{
					text += "ORDER BY [ww_StartTime] ASC";
				}
				else
				{
					if (ww_StartTimeUp == 2)
					{
						text += "ORDER BY [ww_StartTime] DESC";
					}
				}
				if (ww_EndTimeUp == 1)
				{
					text += "ORDER BY [ww_EndTime] ASC";
				}
				else
				{
					if (ww_EndTimeUp == 2)
					{
						text += "ORDER BY [ww_EndTime] DESC";
					}
				}
			}
			return this.conn.GetDataTable(text);
		}
		public DataTable GetWitkeyUser(int Uid, int type, string Title, int Statu)
		{
			string text = string.Empty;
			text = string.Concat(new object[]
			{
				"SELECT [ww_Id],[ww_Type],[ww_Mode],[ww_xsModel],[ww_Title] ,[ww_Content],[ww_WitkeyTypeOne],[ww_WitkeyTypeTwo]  ,[ww_Uid],[ww_UserName],[ww_StartTime],[ww_EndTime],[ww_zbPrice],[ww_xsPrice],[ww_Participants],[ww_Complete],[ww_Top],[ww_Url] ,[work_Id],[work_WitkeyId],[work_Uid],[work_UserName],[work_Title],[work_Desc],[work_File],[work_Date],[work_statu],CASE WHEN [ww_Statu] =1 THEN '未付款' WHEN [ww_Statu] =2 THEN '待审核' WHEN [ww_Statu] =3 THEN '审核失败'   WHEN [ww_Statu] =4 THEN '进行中' WHEN [ww_Statu] =5 THEN '公示中' WHEN [ww_Statu] =6 THEN '投票中' WHEN [ww_Statu] =7 THEN '任务失败'  WHEN [ww_Statu] =9 THEN '冻结' WHEN [ww_Statu] =8 THEN '任务结束' END AS [ww_Statu] FROM [HLWitkey_Witkey],[HLWitkey_Work] WHERE [ww_Id] = [work_WitkeyId]  AND [work_Uid] = ",
				Uid,
				"AND ww_Type = ",
				type
			});
			if (Statu != 0)
			{
				text = text + " AND [ww_Statu] = " + Statu;
			}
			if (Title.Trim() != "")
			{
				text = text + " AND [ww_Title] = " + Title;
			}
			text += " ORDER BY ww_StartTime DESC";
			return this.conn.GetDataTable(text);
		}
		public DataTable AddWitkey(int ww_Type, string ww_Mode, string ww_Title, string ww_Content, string ww_WitkeyTypeOne, string ww_WitkeyTypeTwo, int ww_Uid, string ww_UserName, DateTime ww_StartTime, DateTime ww_EndTime, string ww_zbPrice, decimal ww_xsPrice, int ww_Top, string ww_Url, int ww_Statu, string ww_xsModel, string ww_Email, string ww_Phone)
		{
			SqlParameter[] array = new SqlParameter[18];
			array[0] = new SqlParameter("@ww_Type", DbType.Int32);
			array[0].Value = ww_Type;
			array[1] = new SqlParameter("@ww_Mode", DbType.String);
			array[1].Value = ww_Mode;
			array[2] = new SqlParameter("@ww_Title", DbType.String);
			array[2].Value = ww_Title;
			array[3] = new SqlParameter("@ww_Content", DbType.String);
			array[3].Value = ww_Content;
			array[4] = new SqlParameter("@ww_WitkeyTypeOne", DbType.String);
			array[4].Value = ww_WitkeyTypeOne;
			array[5] = new SqlParameter("@ww_WitkeyTypeTwo", DbType.String);
			array[5].Value = ww_WitkeyTypeTwo;
			array[6] = new SqlParameter("@ww_Uid", DbType.Int32);
			array[6].Value = ww_Uid;
			array[7] = new SqlParameter("@ww_UserName", DbType.String);
			array[7].Value = ww_UserName;
			array[8] = new SqlParameter("@ww_StartTime", DbType.DateTime);
			array[8].Value = ww_StartTime;
			array[9] = new SqlParameter("@ww_EndTime", DbType.DateTime);
			array[9].Value = ww_EndTime;
			array[10] = new SqlParameter("@ww_zbPrice", DbType.String);
			array[10].Value = ww_zbPrice;
			array[11] = new SqlParameter("@ww_xsPrice", DbType.Decimal);
			array[11].Value = ww_xsPrice;
			array[12] = new SqlParameter("@ww_Top", DbType.Int32);
			array[12].Value = ww_Top;
			array[13] = new SqlParameter("@ww_Url", DbType.String);
			array[13].Value = ww_Url;
			array[14] = new SqlParameter("@ww_Statu", DbType.Int32);
			array[14].Value = ww_Statu;
			array[15] = new SqlParameter("@ww_xsModel", DbType.String);
			array[15].Value = ww_xsModel;
			array[16] = new SqlParameter("@ww_Email", DbType.String);
			array[16].Value = ww_Email;
			array[17] = new SqlParameter("@ww_Phone", DbType.String);
			array[17].Value = ww_Phone;
			return this.conn.GetDataTable("PR_AddWitkey", array);
		}
		public void UpdateWitkeyStatu(int WitkeyId, int Statu)
		{
			string sql = string.Empty;
			sql = "UPDATE [HLWitkey_Witkey] SET [ww_Statu] =  " + Statu.ToString() + " WHERE [ww_Id] = " + WitkeyId.ToString();
			this.conn.Execute(sql);
		}
		public void UpdateWitkey(int ww_ID, string ww_Title, string ww_Content, string ww_WitkeyTypeOne, string ww_WitkeyTypeTwo, string ww_UserName, string ww_xsModel, string ww_Email, string ww_Phone)
		{
			SqlParameter[] array = new SqlParameter[9];
			array[0] = new SqlParameter("@ww_ID", DbType.Int32);
			array[0].Value = ww_ID;
			array[1] = new SqlParameter("@ww_Title", DbType.String);
			array[1].Value = ww_Title;
			array[2] = new SqlParameter("@ww_Content", DbType.String);
			array[2].Value = ww_Content;
			array[3] = new SqlParameter("@ww_WitkeyTypeOne", DbType.String);
			array[3].Value = ww_WitkeyTypeOne;
			array[4] = new SqlParameter("@ww_WitkeyTypeTwo", DbType.String);
			array[4].Value = ww_WitkeyTypeTwo;
			array[5] = new SqlParameter("@ww_UserName", DbType.String);
			array[5].Value = ww_UserName;
			array[6] = new SqlParameter("@ww_xsModel", DbType.String);
			array[6].Value = ww_xsModel;
			array[7] = new SqlParameter("@ww_Email", DbType.String);
			array[7].Value = ww_Email;
			array[8] = new SqlParameter("@ww_Phone", DbType.String);
			array[8].Value = ww_Phone;
			this.conn.Execute("PR_UpdateWitkey", array);
		}
		public void UpdateWitkey(int ww_ID, string ww_Title, string ww_Content, string ww_WitkeyTypeOne, string ww_WitkeyTypeTwo, string ww_UserName, string ww_xsModel, string ww_Email, string ww_Phone, string Price, int ww_Statu)
		{
			string text = string.Empty;
			text = string.Concat(new object[]
			{
				"UPDATE [HLWitkey_Witkey] SET [ww_Statu] = ",
				ww_Statu,
				",ww_Title = '",
				ww_Title,
				"',ww_Content = '",
				ww_Content,
				"',ww_WitkeyTypeOne = '",
				ww_WitkeyTypeOne,
				"',ww_WitkeyTypeTwo = '",
				ww_WitkeyTypeTwo,
				"',ww_UserName = '",
				ww_UserName,
				"',ww_xsModel = '",
				ww_xsModel,
				"',ww_Email = '",
				ww_Email,
				"',ww_Phone = '",
				ww_Phone,
				"'"
			});
			if (ww_xsModel.Trim() != "")
			{
				text = text + " , [ww_xsPrice] = '" + Price + "'";
			}
			else
			{
				text = text + " , [ww_zbPrice] =  '" + Price + "'";
			}
			text = text + " WHERE [ww_Id] = " + ww_ID;
			this.conn.Execute(text);
		}
		public void UpdateWitkeyCount(int ww_ID, int ww_Participants, int ww_Complete)
		{
			string sql = string.Empty;
			sql = string.Concat(new string[]
			{
				"UPDATE [HLWitkey_Witkey] SET [ww_Participants] =  ",
				ww_Participants.ToString(),
				",[ww_Complete] = ",
				ww_Complete.ToString(),
				" WHERE [ww_Id] = ",
				ww_ID.ToString()
			});
			this.conn.Execute(sql);
		}
		public DataTable GetWitkeyAllByType(int ww_Uid, int ww_Type, int indexMode, string ww_xsModel, string ww_WitkeyTypeTwo, int ww_Statu, string title)
		{
			string text = string.Empty;
			text = "SELECT [ww_Id],[ww_Type],[ww_Mode],[ww_xsModel],[ww_Title] ,[ww_Content],[ww_WitkeyTypeOne],[ww_WitkeyTypeTwo] ,[ww_Uid],[ww_UserName],[ww_StartTime],[ww_EndTime],[ww_zbPrice],[ww_xsPrice],[ww_Participants],[ww_Complete],[ww_Top],[ww_Url]       ,CASE WHEN [ww_Statu] =1 THEN '未付款' WHEN [ww_Statu] =2 THEN '待审核' WHEN [ww_Statu] =3 THEN '审核失败'  WHEN [ww_Statu] =4 THEN '进行中' WHEN [ww_Statu] =5 THEN '公示中' WHEN [ww_Statu] =6 THEN '投票中' WHEN [ww_Statu] =7 THEN '任务失败'  WHEN [ww_Statu] =9 THEN '冻结' WHEN [ww_Statu] =8 THEN '任务结束' END AS [ww_Statu] FROM [HLWitkey_Witkey] WHERE [ww_Type] = " + ww_Type;
			if (indexMode == 0)
			{
				text = text + " AND [ww_Uid] =  " + ww_Uid;
			}
			if (ww_xsModel != "")
			{
				text = text + " AND [ww_xsModel] =  '" + ww_xsModel + "'";
			}
			if (ww_WitkeyTypeTwo != "")
			{
				text = text + " AND [ww_WitkeyTypeTwo] like  '%" + ww_WitkeyTypeTwo + "%'";
			}
			if (ww_Statu != 0)
			{
				text = text + " AND [ww_Statu] =  " + ww_Statu;
			}
			if (title.Trim() != "")
			{
				text = text + " AND [ww_Title]  like  '%" + title + "%'";
			}
			text += " ORDER BY ww_StartTime DESC";
			return this.conn.GetDataTable(text);
		}
	}
}
